package com.qingke.exe;

public class SharedCounter {
	
	int counter = 0;
	
	public static void main(String[] args) {
		SharedCounter sc = new SharedCounter();
		
		for (int i = 0; i < 10; i++) {
			Thread t = new Thread(new Counter(sc));
			t.start();
		}
		
	}
}

class Counter implements Runnable {

	SharedCounter sc;
	public Counter(SharedCounter sc) {
		this.sc = sc;
	}
	@Override
	public void run() {
		synchronized(sc) {
		for (int i = 0; i< 10; i++) {
			sc.counter++;
		}
		System.out.println(sc.counter);
		}
	}
	
}
